/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.renren;

import io.renren.common.utils.Configuration;
import io.renren.common.utils.Constant;
import io.renren.datasource.config.DynamicDataSourceConfig;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;


@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@Import({DynamicDataSourceConfig.class})
public class RenrenApplication extends SpringBootServletInitializer
		implements ApplicationContextAware, ServletContextAware {

	@Autowired
	private Environment env;


	public static void main(String[] args) {
		SpringApplication.run(RenrenApplication.class, args);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(RenrenApplication.class);
	}

	/**
	 * 初始化配置环境
	 */
	@Override
	public void setApplicationContext(ApplicationContext ctx) throws BeansException {

		Constant.conf = Configuration.getInstance(env);
	}

	/**
	 * 初始化缓存数据
	 */
	@Override
	public void setServletContext(ServletContext servletContext) {
		try {

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}